

//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Main {
    public static void main(String[] args) {
        System.out.println(add(10));
//        System.out.println(fib(42));
        System.out.println(count);
        System.out.println(fibs(42));
        System.out.println(count);
    }
    static int count = 0;
    public static void print(int n){
        if( n <= 9 ){
            System.out.print(n + " ");
            return;
        }else{
            print(n / 10);
            System.out.print((n % 10) + " ");
        }
    }

    public static int add(int n){
        if(1 == n){
            return 1;
        }else{
            return n + add(n - 1);
        }
    }

    public static int fib(int n){
        if( n == 1 || n == 2){
            count++;
            return 1;
        }else{
            count++;
            return (fib(n - 1) + fib(n - 2));
        }
    }

    public static int fibs(int n){

        if(n == 1){
            count++;
            return 0;
        }else if(n == 2 || n == 3){
            count++;
            return 1;
        }else{
            int f1 = 1,f2 = 1;
            while(n - 3 > 0){
                int tmp = f2;
                f2 = f1 + f2;
                f1 = tmp;
                n--;
                count++;
            }
            return f2;
        }
    }
}